package cn.wolfcode.qo;

import lombok.Getter;

import java.util.List;

@Getter
public class PageResult<T> {
    private List<T> data;//数据
    private int currentPage;//当前页
    private int pageSize;//每条页数
    private int totalCount;//总数量

    //上面要不是传过来，要不就是数据库查询出来
    //下面是计算出来

    private int prevPage;//上一页
    private int nextPage;//下一页
    private int totalPage;//总页数

    public PageResult(List<T> data, int currentPage, int pageSize, int totalCount) {
        this.data = data;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;

        if (totalCount <= pageSize) {
            this.totalPage = 1;
            this.prevPage = 1;
            this.nextPage = 1;
            return;
        }

        this.totalPage = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
        this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage - 1 : 1;
        this.nextPage = this.currentPage + 1 <= this.totalPage ? this.currentPage + 1 : this.totalPage;
    }
}
